<%@ page contentType="text/html; charset=utf-8" language="java" pageEncoding="utf-8" %>
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>开发文档-数据点</title>
		<link type="text/css" rel="stylesheet" href="css/pages/xlink/global.css">
		<link type="text/css" rel="stylesheet" href="css/pages/xlink/developer.css">
	</head>
	<body>
		<div id="top">
			<div id="top_logo"><span>Xlink</span></div>
			<div id="top_right">
				<div id="top_right_ul1"> 
				    <ul>
				    	<li><a href="contact.html">联系我们</a></li>
				    	<li><a href="#">工作机会</a></li>
				    	<li><a href="mydevice.html">用户中心</a></li>
				    </ul>
				</div>
				<div id="top_right_ul2">
					<ul>
					<li><a hre="index.html">首页</a></li>
					<li><a hre="developer.html">开发者</a></li>
					<li><a hre="#">搜索</a></li>
					<li><a hre="#">社区</a></li>
					<li><a hre="#">博客</a></li>
					<li><a hre="contact.html">联系我们</a></li>
					</ul>
				</div>
			</div>
		</div>

		<div id="banner" class="short bg8">
			<div class="inset">
				<h1>数据点 Datapoints</h1>
				<p>一个datapoint是由key和value组成的键值对.</p>
			</div>
		</div>

		<div id="first">
			<div id="left">
				<h1>导航中心</h1>
				<ul>
					<li><a href="#">快速开始</a></li>
					<li><a href="#">开发例程</a></li>
					<li><a href="#">案例分析</a></li>
					<li><a href="#">移动客户端</a></li>
					<li><a href="#">API文档</a></li>
					<li><a href="#">使用条款</a></li>
				</ul>
			</div>
			<div id="right">
					
				<div id="developer_main" class="devdoc">
					<h1>API文档 <i>(版本1.0，版本 <a href="#">v1.1</a> 测试中)</i></h1>
					<h2>数据点 Datapoints</h2>
					<p class="info">一个datapoint是由key和value组成的键值对.</p>
					<table id="table_device" class="common">
						<thead>
							<tr><th colspan="3">API列表</th></tr>
						</thead>
						<tbody>
							<tr><td><a href="#">/v1.0/datapoint/&lt;device_id&gt;/&lt;sensor_id&gt;/</a></td><td width="320">创建数据点</td><td width="80"><a href="#" target="_blank">在线调试</a></td></tr>
							<tr><td><a href="#">/v1.0/datapoint/&lt;device_id&gt;/&lt;sensor_id&gt;/&lt;key&gt;</a></td><td width="320">编辑数据点</td><td width="80"><a href="#" target="_blank">在线调试</a></td></tr>
							<tr><td><a href="#">/v1.0/datapoint/&lt;device_id&gt;/&lt;sensor_id&gt;/&lt;key&gt;</a></td><td width="320">查看数据点</td><td width="80"><a href="#" target="_blank">在线调试</a></td></tr>
							<tr><td><a href="#">/v1.0/datapoint/&lt;device_id&gt;/&lt;sensor_id&gt;/&lt;key&gt;</a></td><td width="320">删除数据点</td><td width="80"><a href="#" target="_blank">在线调试</a></td></tr>
						</tbody>
					</table>
							<h3><a id="anchor_25" class="local" name="anchor_25"></a>创建数据点</h3>
							<p class="info">对该URL的一个HTTP POST请求会为指定的传感器创建一个新的数据点, 使用此API来为传感器存储历史数据.</p>
					<h4>URL</h4>
					<p>	http://api.Xlink.net/v1.0/datapoint/&lt;device_id&gt;/&lt;sensor_id&gt;/</p>
					<p class="note"><em>Note: </em>目前限定相邻数据上传间隔须大于等于10s, 过于频繁的请求会收到406 Response.</p>
					<h4>请求参数</h4>
					<table class="common">
						<thead>
							<tr><th>参数名</th><th>必需</th><th>类型</th><th>说明</th></tr>
						</thead>
						<tbody>
							<tr><th>device_id</th><td>true</td><td>int</td><td>设备ID</td></tr>
							<tr><th>sensor_id</th><td>true</td><td>int</td><td>传感器ID</td></tr>
						</tbody>
					</table>
					<h4>数据格式</h4>
					<p>JSON</p>
					<h4>数据格式说明</h4>
						<p>一个datapoint是由key和value组成的键值对.</p>
						<table class="common">
							<thead>
								<tr><th width="100">参数名</th><th width="50">必需</th><th width="80">类型</th><th>说明</th></tr>
							</thead>
							<tbody>
							    <tr><th>key</th><td>true</td><td>timestamp</td><td>键</td></tr>
								<tr><th>value</th><td>true</td><td>binary</td><td>值</td></tr>
							</tbody>
						</table>
					
						<div class="tabs">
							<ul class="tab">
								<li class="select">数值型传感器</li>
								<li>GPS型传感器</li>
								<li>泛型传感器</li>
								<li>图像传感器</li>
								<li>微博抓取器</li>
							</ul>
							<ul class="tab_content">
								<li style="display: list-item;"><p>key为timestamp, value为数值</p></li>
								<li style="display: none;"><p>key为timestamp, value为JSON格式, 由经度、纬度、速度等GPS信息组成; 同时可以指定是否修正地图上显示的偏移.</p></li>
								<li style="display: none;"><p>key为用户自定义字符串, 大小限定为128个字符; value为JSON格式,由用户自定义具体内容, 大小限定为1024个字符.</p></li>
								<li style="display: none;"><p>key为timestamp, value为图像二进制信息;</p></li>
								<li style="display: none;"><p>不支持</p></li>
							</ul>
						</div>

			<p class="note"><em>Note</em>: key为唯一索引; timestamp为ISO 8601标准时间格式(默认时区为中国标准时间CST), 例如：2012-03-15T16:13:14.</p>
			<h4>单个上传数据例子(JSON)</h4>
			<div class="tabs">
							<ul class="tab">
								<li class="select">数值型传感器</li>
								<li>GPS型传感器</li>
								<li>泛型传感器</li>
							</ul>
							<ul class="tab_content">
								<li style="display: list-item;"><pre>{
			  "timestamp":"2012-03-15T16:13:14",
			  "value":294.34
			}
			</pre></li>
								<li style="display: none;"><pre>{
			  "timestamp":"2012-03-15T16:13:14",
			  "value":{"lat":35.4567,"lng":46.1234,"speed":98.2}
			}</pre>

									<pre>{
			  "timestamp":"2012-03-15T16:13:14",
			  "value":{"lat":35.4567,"lng":46.1234,"speed":98.2,"offset":"yes"}
			}
			</pre>
								</li>
								<li style="display: none;"><pre>{
			  "key":"e10adc3949ba59abbe56e037f20f884e",
			  "value":{...}
			}</pre>

								</li>
							</ul>
						</div>
			<h4>批量上传数据例子(JSON)</h4>

			<div class="tabs">
							<ul class="tab">
								<li class="select">数值型传感器</li>
								<li>GPS型传感器</li>
								<li>泛型传感器</li>
							</ul>
							<ul class="tab_content">
								<li style="display: list-item;"><pre>[
			  {"timestamp": "2012-06-15T14:00:00", "value":315.01},
			  {"timestamp": "2012-06-15T14:00:10", "value":316.23},
			  {"timestamp": "2012-06-15T14:00:20", "value":317.26},
			  {"timestamp": "2012-06-15T14:00:30", "value":318},
			  {"timestamp": "2012-06-15T14:00:40", "value":317}
			]
			</pre></li>
								<li style="display: none;">暂不支持</li>
								<li style="display: none;">暂不支持</li>
							</ul>
						</div>
					<h4>Method</h4>
					<p>POST</p>
					<h4>返回值</h4>
					<p>HTTP Headers only</p>
					<h4>访问授权</h4>
					<p>需要在HTTP Header中增加API Key来授权写入操作, 具体请参照<a href="#">API Key</a>.</p>	
					<h4>请求实例 (运用curl):</h4>
					<div class="tabs">
						<ul class="tab"><li class="select">CURL</li></ul>
						<ul class="tab_content">
							<li style="display: list-item;"><pre>curl --request POST --data-binary @datafile.txt
				 --header "U-ApiKey: YOUR_API_KEY_HERE" http://api.Xlink.net/v1.0/datapoint/12/3</pre>
					<p class="note"><em>Note:</em>需要在HTTP Header中增加API Key来授权写入操作, 具体请参照<a href="#">API Key</a>. 支持一次传送一个数据或者批量上传.</p></li>
						</ul>
					</div>				<h3><a id="anchor_26" class="local" name="anchor_26"></a>编辑数据点</h3>
							<p class="info">根据设备ID编辑已经接入的数据点.</p>
					<h4>URL</h4>
					<p>http://api.Xlink.net/v1.0/datapoint/&lt;device_id&gt;/&lt;sensor_id&gt;/&lt;key&gt;</p>
					<p class="note"><em>Note: </em>对该<code>URL</code>的一个<code>HTTP PUT</code>请求将更新指定数据,其中&lt;device_id&gt;为所要更新的数据所属设备的id,&lt;sensor_id&gt;为所要更新的数据所属的传感器的id.若您的客户端不支持PUT请求, 请使用url方式模拟, 具体参照模拟PUT, DELETE请求.</p>
					<h4>请求参数</h4>
					<table class="common">
						<thead>
							<tr><th width="100">参数名</th>
								<th width="50">必需</th>
								<th width="80">类型</th>
								<th>说明</th></tr>
						</thead>
						<tbody>
							<tr><th>device_id</th><td>true</td><td>string</td><td>设备ID</td></tr>
							<tr><th>sensor_id</th><td>true</td><td>string</td><td>传感器ID</td></tr>
							<tr><th>key</th><td>true</td><td>string</td><td>为所要更新数据的时间戳(ISO 8601格式)</td></tr>
						</tbody>
					</table>
					<h4>Method</h4>
					<p>PUT</p>
					<h4>返回值</h4>
					<p>HTTP Headers only</p>
					<h4>数据格式</h4>
					<p>JSON</p>
					<h4>数据格式说明</h4>
					<div class="tabs">
						<ul class="tab">
							<li class="select">数值型传感器</li>
							<li>GPS型传感器</li>
							<li>泛型传感器</li>
						</ul>
						<ul class="tab_content">
							<li style="display: list-item;">
								<table class="common">
									<thead>
										<tr><th width="100">参数名</th>
								<th width="50">必需</th>
								<th width="80">类型</th>
								<th>说明</th></tr>
									</thead>
									<tbody>
										<tr><th>value</th><td>true</td><td>float</td><td>值</td></tr>
									</tbody>
								</table>
								<pre>{
			  "value": 39.4
			}</pre>
							</li>
							<li style="display: none;">
								<table class="common">
									<thead>
										<tr><th width="100">参数名</th>
								<th width="50">必需</th>
								<th width="80">类型</th>
								<th>说明</th></tr>
									</thead>
									<tbody>
										<tr><th>value</th><td>true</td><td>json</td><td>{"lat":35.4321,"lng":46.3451,"speed":98.2}</td></tr>
									</tbody>
								</table>
								<pre>{
				"value": {"lat":35.4321,"lng":46.3451,"speed":98.2}
			}</pre>
							</li>
							<li style="display: none;">
								<table class="common">
									<thead>
										<tr><th width="100">参数名</th>
								<th width="50">必需</th>
								<th width="80">类型</th>
								<th>说明</th></tr>
									</thead>
									<tbody>
										<tr><th>value</th><td>true</td><td>json</td><td>json</td></tr>
									</tbody>
								</table>
								<pre>{
				"value": {...}
			}</pre>
							</li>
						</ul>
					</div>
					
					<h4>请求实例 </h4>
					<div class="tabs">
						<ul class="tab">
							<li class="select">CURL</li>
						</ul>
						<ul class="tab_content">
							<li style="display: list-item;">
								<p>数值型传感器和gps型传感器, &lt;key&gt;为所要更新数据的时间戳(ISO 8601格式).</p>
								<pre>curl --request PUT --data-binary @datafile.txt 
				--header "U-ApiKey: YOUR_API_KEY_HERE" 
					http://api.Xlink.net/v1.0/datapoint/12/3/2012-03-15T16:13:14</pre>
								<p>泛型传感器, &lt;key&gt;为用户自定义的字符串, 在请求的URL中需要做urlencode.</p>
								<pre>curl --request PUT --data-binary @datafile.txt 
				--header "U-ApiKey: YOUR_API_KEY_HERE" 
					http://api.Xlink.net/v1.0/datapoint/12/3/2012-03-15T16:13:14</pre>
								
								<p>微博抓取器不支持;</p>
								<p class="note"><em>Note:</em>只需将要修改的数据值放到datafile.txt中,需要在HTTP Header中增加API Key来授权写入操作, 具体请参照API Key. </p>
							</li>
						</ul>
					</div>
			       				<h3><a id="anchor_27" class="local" name="anchor_27"></a>查看数据点</h3>
							<p class="info">对该URL的请求返回指定key的datapoint, 若未指定key, 则返回该sensor的最新数据.</p>
					<h4>URL</h4>
					<p>http://api.Xlink.net/v1.0/datapoint/&lt;device_id&gt;/&lt;sensor_id&gt;/&lt;key&gt;</p>
					<h4>请求参数</h4>
					<table class="common">
						<thead>
							<tr><th width="100">参数名</th><th width="100">必需</th><th width="100">类型</th><th>说明</th></tr>
						</thead>
						<tbody>
							<tr>
							<th>device_id</th><td>true</td><td>string</td><td>设备ID</td></tr>
							<tr><th>sensor_id</th><td>true</td><td>string</td><td>传感器ID</td></tr>
							<tr><th>key</th><td>true</td><td>string</td><td>数值和GPS型为数据的时间戳，泛型为自定义字符串</td></tr>
						</tbody>
					</table>
				   <h4>Method</h4>
					<p>GET</p>
					<h4>返回值</h4>
					<p>请求的传感器信息</p>
					<h4>返回值数据格式</h4>
					<p>JSON</p>
					<h4>返回值数据格式说明</h4>
					<p>添加Key</p>
					<div class="tabs">
						<ul class="tab">
							<li class="select">数值型传感器</li>
							<li>gps型传感器</li>
							<li>泛型传感器</li>
							<li>微博抓取器</li>
						</ul>
						<ul class="tab_content">
							<li style="display: list-item;"><pre>{
			  "value": 39.4
			}</pre></li>
							<li style="display: none;"><pre>{
			 "value": {"lat":35.4321,"lng":46.3451,"speed":98.2}
			}</pre></li>
							<li style="display: none;"><pre>{
			 "value": {...}
			}</pre></li>
							<li style="display: none;">
								<table class="common">
									<thead>
										<tr><th width="100">参数名</th><th width="100">必需</th><th width="100">类型</th><th>说明</th></tr>
									</thead>
									<tbody>
										<tr>
										<th>status_cnt</th><td>true</td><td>int</td><td>未读微博数</td></tr>
										<tr><th>follower_cnt</th><td>true</td><td>int</td><td>新增好友数</td></tr>
										<tr><th>msg_cnt</th><td>true</td><td>int</td><td>新消息数</td></tr>
									</tbody>
								</table>
								<pre>{
			  "status_cnt":0,"follower_cnt":0,"msg_cnt":0
			}</pre></li>
						</ul>
					</div>
					<p>未添加Key</p>
					<div class="tabs">
						<ul class="tab">
							<li class="select">数值型传感器</li>
							<li>gps型传感器</li>
							<li>泛型传感器</li>
						</ul>
						<ul class="tab_content">
							<li style="display: list-item;"><pre>{
				"timestamp":"2012-03-15T16:13:14",
				"value": 39.2
			}</pre></li>
							<li style="display: none;"><pre>{
				"timestamp":"2012-03-15T16:13:14",
				"value": {"lat":35.4321,"lng":46.3451,"speed":98.2}
			}</pre></li>
							<li style="display: none;"><pre>{
				"key":"e10adc3949ba59abbe56e037f20f884e",
				"value": {...}
			}</pre></li>
						</ul>
					</div>
					<h4>访问授权</h4>
					<p>需要在HTTP Header中增加API Key来授权GET操作, 具体请参照<a href="#">API Key</a>.</p>
					
				
					<h4>请求实例</h4>
					<div class="tabs">
						<ul class="tab"><li class="select">CURL</li></ul>
						<ul class="tab_content">
							<li style="display: list-item;">
							<p class="note"><em>Note:</em>对于数值型传感器和gps型传感器, &lt;key&gt;为所要查看数据的时间戳(ISO 8601格式).</p>
							<pre>curl --request GET --header "U-ApiKey: YOUR_API_KEY_HERE" 
				http://api.Xlink.net/v1.0/datapoint/12/3/2012-03-15T16:13:14</pre>
							<p class="note"><em>Note:</em>对于泛型传感器, <key>为用户自定义的字符串, 在请求的URL中需要做urlencode.</key></p>
							<pre>curl --request GET --header "U-ApiKey: YOUR_API_KEY_HERE"
				http://api.Xlink.net/v1.0/datapoint/12/3/e10adc3949ba59abbe56e037f20f884e</pre>
							<p class="note"><em>Note:</em>微博抓取器 不支持参数key;</p>
					</li>
						</ul>
					</div>				<h3><a id="anchor_28" class="local" name="anchor_28"></a>删除数据点</h3>
							<h4>URL</h4>
					<p>http://api.Xlink.net/v1.0/datapoint/&lt;device_id&gt;/&lt;sensor_id&gt;/&lt;key&gt;</p>
					<p class="note"><em>Note:</em>对该<code>URL</code>的一个<code>HTTP DELETE</code>请求将删除指定&lt;key&gt;的数据, 其中&lt;sensor_id&gt;为所要删除的数据所属传感器的id,&lt;device_id&gt;为所要删除的数据所属设备的id. 若您的客户端不支持DELETE请求, 请使用url方式模拟, 具体参照模拟PUT, DELETE请求.</p>
					<h4>Method</h4>
					<p>DELETE</p>
					<h4>返回值</h4>
					<p>HTTP Headers only</p>
					<h4>数据格式</h4>
					<p>JSON</p>
					<h4>数据格式说明</h4>
					<table class="common">
						<thead>
							<tr><th width="100">参数名</th><th width="100">必需</th><th width="100">类型</th><th>说明</th></tr>
						</thead>
						<tbody>
							<tr>
							<th>device_id</th><td>true</td><td>string</td><td>设备ID</td></tr>
							<tr><th>sensor_id</th><td>true</td><td>string</td><td>传感器ID</td></tr>
							<tr><th>key</th><td>true</td><td>string</td><td>数值和GPS型为数据的时间戳，泛型为自定义字符串</td></tr>
						</tbody>
					</table>
					<h4>访问授权</h4>
					<p>需要在HTTP Header中增加API Key来授权DELETE操作, 具体请参照<a href="#">API Key</a>.</p>
					<h4>请求实例 (运用curl)：</h4>
					<div class="tabs">
						<ul class="tab"><li class="select">CURL</li></ul>
						<ul class="tab_content">
							<li style="display: list-item;"><pre>curl --request DELETE --header "U-ApiKey: YOUR_API_KEY_HERE" 
			  --http://api.Xlink.net/v1.0/datapoint/12/3/2012-03-15T16:13:14</pre>
					<p class="note"><em>Note:</em>对于数值型传感器和gps型传感器, &lt;key&gt;为所要更新数据的时间戳(ISO 8601格式).</p>
					<pre>curl --request DELETE --header "U-ApiKey: YOUR_API_KEY_HERE" 
			  --http://api.Xlink.net/v1.0/datapoint/12/3/e10adc3949ba59abbe56e037f20f884e</pre>
			  <p class="note"><em>Note:</em>对于泛型传感器, &lt;key&gt;为用户自定义的字符串, 在请求的URL中需要做urlencode.</p>
			  </li>
			</ul>
					</div>					
					<div class="doc_nav">
						<h4>快速导航</h4>
						<ul>
											<li><a href="#">创建数据点</a></li>
											<li><a href="#">编辑数据点</a></li>
											<li><a href="#">查看数据点</a></li>
											<li><a href="#">删除数据点</a></li>
										</ul>
						
						<div class="navbar"><a class="gotop">GO TOP</a></div>
					</div>
						</div>

			</div>
		</div>
		<div id="bottom">@Xlink 版权所有</div>
		<script type="text/javascript">
		var _bdhmProtocol = (("https:" == document.location.protocol) ? " https://" : " http://");
		document.write(unescape("%3Cscript src='" + _bdhmProtocol + "hm.baidu.com/h.js%3F5f94f1c230854f8066134ebed007b8c7' type='text/javascript'%3E%3C/script%3E"));
		</script>
		<script src="../../../js/pages/xlink/h.js" type="text/javascript"></script>
		<script src="../../../js/pages/xlink/sea-debug.js" data-config="/resource/js/config" data-main="/resource/js/main"></script>
		<script>
		seajs.use(['/resource/js/scroller', '/resource/js/devnav', '/resource/js/searchbar', '/resource/js/devdocnav', '/resource/js/tab'], function(scroller, devnav, Searchbar, devDocnav, tab){
			var Scroller = scroller.Scroller;
			var partnersScroller = new Scroller({
				container: '#forums .mask',
				navBars: {
					prev: '#forums .navbar .prev',
					next: '#forums .navbar .next'
				},
				contentWidth: 1440,
				containerWidth: 815,
				stepLength: 150
			});
			
			var creatorScroller = new Scroller({
				container: '#creator .box',
				navBars: {
					prev: '#creator .navbar .prev',
					next: '#creator .navbar .next'
				},
				contentWidth: 860,
				containerWidth: 430,
				stepLength: 430
			});
			
			devnav.init();
			
			new Searchbar({
				
			});
			new Searchbar({
					container: '#header .subnav .searchbar',
					input: '#header .subnav .searchbar input',
					button: '#header .subnav .searchbar button',
					direction: 'down'
			});
			
			devDocnav.init({
				rel: '#table_device'
			})
			
			tab({
				s_container: '.tabs',
				s_tab: '.tab>li',
				s_content: '.tab_content>li'
			});
		});
		</script>
	</body>
</html>
